import uvm_pkg::*;
`include "uvm_macros.svh"



class mpi_adapter extends uvm_reg_adapter;
	uvm_sequence_item proto;
	`uvm_object_utils(mpi_adapter)
	extern function new(string name = "mpi_adapter");
	extern virtual function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);
	extern virtual function void bus2reg(uvm_sequence_item bus_item,ref uvm_reg_bus_op rw);
endclass: mpi_adapter

function mpi_adapter::new(string name = "mpi_adapter");
	super.new(name);
endfunction: new

function uvm_sequence_item mpi_adapter::reg2bus(const ref uvm_reg_bus_op rw);
	mpi_xaction tr;
	
	if(!$cast(tr,proto.create()))begin
		`uvm_fatal(get_type_name(), "reg2bus(): Proto is not of type mpi_xaction or its extension");
	end
	
	tr.op_type = (rw.kind == UVM_READ) ? 0 : 1;
	tr.addr = rw.addr;
	tr.data = rw.data;
	`uvm_info(get_type_name(), $sformatf("reg2bus(): Translating uvm_reg_bus_op into %s:\n %s",tr.get_type_name,tr.sprint()),UVM_HIGH);
	
	return tr;
endfunction: reg2bus

function void mpi_adapter::bus2reg(uvm_sequence_item bus_item,ref uvm_reg_bus_op rw);
	mpi_xaction tr;
	
	if(!$cast(tr, bus_item))begin
		`uvm_fatal(get_type_name(), "bus2reg(): Bus item is not of type CPU_xation or its extension");
		return;
	
	end
	
	rw.kind = (tr.op_type == 0) ? UVM_READ : UVM_WRITE;
	rw.addr = tr.addr;
	rw.data = tr.data;
	rw.status = UVM_IS_OK;
	`uvm_info(get_type_name(), $sformatf("bus2reg(): Translating %s into uvm_reg_bus_op %s:\n %s",tr.get_type_name,tr.get_type_name,tr.sprint()),UVM_LOW);
endfunction: bus2reg
